<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../layui/css/layui.css">
    <style>
        body {
            padding: 30px 50px 30px 10px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="#" method="post" id="form-user-add">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名称</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" required  lay-verify="required" placeholder="请输入用户名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户密码</label>
        <div class="layui-input-block">
            <input type="password" id="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户地址</label>
        <div class="layui-input-block">
            <input type="text" id="address" name="address" required lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">创建人</label>
        <div class="layui-input-block">
            <input type="text" id="createBy" name="createBy" required lay-verify="required" placeholder="请输入创建人" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-block">
            <input type="text" id="createdate" name="createdate" required lay-verify="required" placeholder="请输入创建时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="btn_save_user" lay-filter="demo1">提交</button>
        </div>
    </div>
</form>
<!--<script type="text/javascript" src="../statics/js/jquery.min.js"></script>-->
<script type="text/javascript" src="../layui/layui.all.js"></script>
<!--<script type="text/javascript" src="../statics/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="../statics/validate/messages_zh.min.js"></script>
<script type="text/javascript" src="../statics/validate/jquery.validate.extend.js"></script>-->
<script>
    layui.use(['form', 'layer','laydate','jquery'], function (form, layer,laydate,$) {
        laydate.render({
            elem: '#createdate'
            ,type: 'datetime'
            ,position: 'fixed'
        });
        $("#btn_save_user").click(function () {
            $.post('user?opr=addSave', $('#form-user-add').serialize(), function(str) {
                if(str > 0){
                    //location.href="toindex.action";
                    layer.msg('添加成功', {
                        icon: 1,//提示的样式
                        time: 1000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
                        end:function(){
                            parent.location.href='user?opr=open';
                        }
                    });
                } else {
                    layer.msg('添加失败', {
                        icon: 2,//提示的样式
                        time: 1000, //2秒关闭（如果不配置，默认是3秒）//设置后不需要自己写定时关闭了，单位是毫秒
                    });
                }
            });
        })
    });
</script>
</body>
</html>